<?php

namespace app\common\model;

class CourseChapter extends Base
{
    /**
     * getListByCourseId
     * @param $course_id
     * @param $field
     * @return array
     * @throws
     */
    public function getListByCourseId($course_id, $field = '*'): array
    {
        $where = [
            'a.course_id' => $course_id,
            'a.status' => 1,
        ];
        $list = $this
            ->alias('a')
            ->leftJoin('course b', "a.course_id = b.id")
            ->where($where)
            ->field($field)
            ->order(['a.sort' => 'desc', 'id' => 'asc'])
            ->select();
        return $list ? $list->toArray() : [];
    }
}